package com.by.basicweb.jsonserializer;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.by.toolkit.consts.DatePatternConst;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * 序列化LocalDateTime
 *
 * @author YanBingHao
 * @since 2023/12/29
 */
public class LocalDateTimeJsonSerializable extends JsonSerializer<LocalDateTime> {

    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(LocalDateTimeUtil.format(value, DatePatternConst.DATE_TIME_PATTERN));
    }
}
